﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;
using System.Diagnostics;

namespace Cherry.Agile.ServiceModel.Routing {
    public sealed class ServiceMessageFilter : MessageFilter {
       
        public override bool Match(System.ServiceModel.Channels.Message message) {
            throw new NotImplementedException();
        }

        public override bool Match(System.ServiceModel.Channels.MessageBuffer buffer) {
            throw new NotImplementedException();
        }

        protected override IMessageFilterTable<FilterData> CreateFilterTable<FilterData>() {
            return new ServiceMessageFilterTable<FilterData>();
        }
    }

    class ServiceMessageFilterTable<TFilterData> : IMessageFilterTable<TFilterData> {

        IServiceMessageReadWriteRoundRobin router = new ServiceMessageReadWriteRoundRobin();

        public bool GetMatchingFilter(MessageBuffer messageBuffer, out MessageFilter filter) {
            throw new NotImplementedException();
        }

        public bool GetMatchingFilter(Message message, out MessageFilter filter) {
            throw new NotImplementedException();
        }

        public bool GetMatchingFilters(MessageBuffer messageBuffer, ICollection<MessageFilter> results) {
            throw new NotImplementedException();
        }

        public bool GetMatchingFilters(Message message, ICollection<MessageFilter> results) {
            throw new NotImplementedException();
        }

        public bool GetMatchingValue(MessageBuffer messageBuffer, out TFilterData value) {
            throw new NotImplementedException();
        }

        public bool GetMatchingValue(Message message, out TFilterData value) {
            value = router.GetMatchingValue<TFilterData>(message);
            return value != null;   
        }

        public bool GetMatchingValues(MessageBuffer messageBuffer, ICollection<TFilterData> results) {
            throw new NotImplementedException();
        }

        public bool GetMatchingValues(Message message, ICollection<TFilterData> results) {
            throw new NotImplementedException();
        }

        public void Add(MessageFilter key, TFilterData value) {
            //throw new NotImplementedException();
        }

        public bool ContainsKey(MessageFilter key) {
            throw new NotImplementedException();
        }

        public ICollection<MessageFilter> Keys {
            get { throw new NotImplementedException(); }
        }

        public bool Remove(MessageFilter key) {
            throw new NotImplementedException();
        }

        public bool TryGetValue(MessageFilter key, out TFilterData value) {
            throw new NotImplementedException();
        }

        public ICollection<TFilterData> Values {
            get { throw new NotImplementedException(); }
        }

        public TFilterData this[MessageFilter key] {
            get {
                throw new NotImplementedException();
            }
            set {
                throw new NotImplementedException();
            }
        }

        public void Add(KeyValuePair<MessageFilter, TFilterData> item) {
            throw new NotImplementedException();
        }

        public void Clear() {
            throw new NotImplementedException();
        }

        public bool Contains(KeyValuePair<MessageFilter, TFilterData> item) {
            throw new NotImplementedException();
        }

        public void CopyTo(KeyValuePair<MessageFilter, TFilterData>[] array, int arrayIndex) {
            throw new NotImplementedException();
        }

        public int Count {
            get { throw new NotImplementedException(); }
        }

        public bool IsReadOnly {
            get { throw new NotImplementedException(); }
        }

        public bool Remove(KeyValuePair<MessageFilter, TFilterData> item) {
            throw new NotImplementedException();
        }

        public IEnumerator<KeyValuePair<MessageFilter, TFilterData>> GetEnumerator() {
            throw new NotImplementedException();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
            throw new NotImplementedException();
        }
    }
}
